<script setup>
import { computed } from 'vue';
import { useTodosStore } from '../store';

const todos = useTodosStore();
// 支持对 state 的数据直接读写，建议不要直接修改，使用actions修改方便维护
todos.active = 'Active';
// 支持对数据重置，但是要求，数据是初始化时候已经确定好，不能是 localStorage.getItem 获取
todos.$reset();
// 替换的是 state 里面的属性
todos.$patch({
  active: 'Completed',
});
const leftCount = computed(() => {
  return todos.list.filter((v) => !v.done).length;
});
</script>

<template>
  <footer class="footer">
    <span class="todo-count"
      ><strong>{{ leftCount }}</strong> item left</span
    >
    <ul class="filters">
      <li
        v-for="item in todos.filterArr"
        :key="item"
        @click="todos.changeActive(item)"
      >
        <a :class="{ selected: item === todos.active }" href="#/">{{ item }}</a>
      </li>
    </ul>
    <button class="clear-completed" @click="todos.clear">
      Clear completed
    </button>
  </footer>
</template>

<style lang="less" scoped></style>
